package org.lisy.java.oop;

/**
 * 抽象类
 * 
 * @author lisy
 */
public class AbstractOperate {

	/**
	 * final
	 * 1.修饰的类不可以被继承
	 * 2.修饰的方法不可以被覆盖
	 * 3.修饰的变量是一个常量，只能被赋值一次
	 * 4.内部类只能访问被final修饰的局部变量
	 */
	/**
	 * 抽象方法一定定义在抽象类中
	 * 抽象方法和抽象类都必须被abstract关键字修饰
	 * 抽象类不可以用new创建对象，因为调用抽象方法没意义
	 * 抽象类中的方法要被使用必须由子类复写其所有的抽象方法后建立子类对象调用 
	 * 	如果子类只覆盖了部分抽象方法，那么该子类还是一个抽象类
	 */
	public static void main(String[] str) {
		Salary s = new Salary("Mohd Mohtashim", "Ambehta, UP", 3, 3600.00);
		Employee e = new Salary("John Adams", "Boston, MA", 2, 2400.00);

		System.out.println("\nCall mailCheck using Salary reference --");
		s.mailCheck();

		System.out.println("\nCall mailCheck using Employee reference--");
		e.mailCheck();
    }
}

abstract class Employee {
	private String name;
	private String address;
	private int number;

	public Employee(String name, String address, int number) {
		System.out.println("Constructing an Employee");
		this.name = name;
		this.address = address;
		this.number = number;
	}

	public abstract double computePay();

	public void mailCheck() {
		System.out.println("Mailing a check to " + this.name + " " + this.address);
	}

	public String toString() {
		return name + " " + address + " " + number;
	}

	public String getName() {
		return name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String newAddress) {
		address = newAddress;
	}

	public int getNumber() {
		return number;
	}
}

class Salary extends Employee{
	private double salary;

	public Salary(String name, String address, int number, double salary) {
		super(name, address, number);
		setSalary(salary);
	}

	public void mailCheck() {
		System.out.println("Within mailCheck of Salary class ");
		System.out.println("Mailing check to" + getName() + "with salary" + salary);
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double newSalary) {
		if (newSalary >= 0.0) {
			salary = newSalary;
		}
	}

	public double computePay() {
		System.out.println("Computing salary pay for " + getName());
		return salary / 52;
	}
}
